package me.zhengjie.util;

/**
 * 文件类型枚举
 *
 * @author guoyuan
 * @version 1.0.0
 * @since 1.0.0
 */
public enum FileTypeEnum {
    /**
     * word文档
     */
    WORD("0", "Word文档"),
    /**
     * pdf文档
     */
    PDF("1", "Pdf文档"),
    /**
     * 表格文档
     */
    EXCEL("2", "Excel表格");

    private String code;

    private String desc;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    FileTypeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static String getType(String suffix) throws Exception {
        String code;
        switch (suffix) {
            case "pdf":
            case "Pdf文档":
                code = PDF.getCode();
                break;
            case "doc":
            case "docx":
            case "Word文档":
                code = WORD.getCode();
                break;
            case "xls":
            case "xlsx":
            case "Excel表格":
                code = EXCEL.getCode();
                break;
            default:
                throw new Exception("文档类型[" + suffix + "]暂不支持");
        }
        return code;
    }

    public static String getDesc(String code) throws Exception {
        String desc;
        switch (code) {
            case "0":
                desc = WORD.getDesc();
                break;
            case "1":
                desc = PDF.getDesc();
                break;
            case "2":
                desc = EXCEL.getDesc();
                break;
            default:
                throw new Exception("文档类型码值[" + code + "]暂不支持");
        }
        return desc;
    }
}
